package com.motu.vertx.module.utility.webhandler;

import com.motu.vertx.module.utility.toolset.TimeUtils;
import com.motu.vertx.module.utility.toolset.Tool;
import com.motu.vertx.module.utility.webtool.BaseWebHandler;
import com.motu.vertx.module.utility.webtool.SearchCondition;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.client.WebClient;
import io.vertx.sqlclient.Pool;

import java.util.ArrayList;
import java.util.List;

public class DownlogHandler extends BaseWebHandler{
	public static final String tableName = "downlog";
	private static Pool jdbcClientServer = null;

	public static void init(Pool jdbcServer){
		jdbcClientServer = jdbcServer;
	}

	public static void search(RoutingContext routingContext,JsonObject json,String adminName,WebClient client){
		List<SearchCondition> scList = new ArrayList<SearchCondition>();
		if (json.containsKey("stime")) {
			json.put("stime", TimeUtils.getTimeStrIntValue(json.getString("stime")));
		}
		if (json.containsKey("etime")) {
			json.put("etime", TimeUtils.getTimeStrIntValue(json.getString("etime")));
		}
		scList.add(new SearchCondition("stime", ">=", new String[]{"addtime"}, null));
		scList.add(new SearchCondition("etime", "<=", new String[]{"addtime"}, null));
		scList.add(new SearchCondition("deviceid", "=", null, null));
		scList.add(new SearchCondition("platform", "=", null, null));
		scList.add(new SearchCondition("version", "=", null, null));

		searchFromTable(routingContext, jdbcClientServer, json, tableName, scList);

	}

}
